import 'package:flutter/material.dart';
import 'package:flutter_github_login/localstorage.dart';
import 'package:get/get.dart';

import '../../models/user.dart';
import '../../routes.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({Key? key}) : super(key: key);

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();
    // 判断用户之前是否登录
    realRunApp();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("启动页"),
    );
  }

  void realRunApp() async{
    // 判断用户之前是否登录
    bool isLogin = await LocalStorage.get("user");
    if(isLogin){
      Navigator.pushReplacementNamed(
          context, Routes.home);
    }else{
      Navigator.pushReplacementNamed(
          context, Routes.login);
    }
  }
}
